<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>供应商管理</title>
</head>
<body>
	<script type="text/javascript">
		//修改
		function updatesuppliers(target) {
			$("#update-suppliers-win").window("open");
		}

		//禁用
		function outbound(target) {
		}

		$(function() {

			//添加供应商
			$("#add-suppliers").click(function() {
				$("#suppliers-win").window("open");
			});

			//添加供应商
			$("#update-suppliers").click(function() {
				$("#update-suppliers-win").window("open");
			});
			
			//确认添加供应商
			$("#save-suppliers").click(function() {
				$('#suppliers-form').form({
				    url:'add-supplier',
				    onSubmit: function(){
				    	// 执行验证    
				        var c=$('#suppliers-form').form("validate");
				        // return false 取消表单提交;
				        return c;
				    },
				    success:function(data){
				    	$(".dissa").text("供应商添加成功！！！");
				    	$("#Dissa").window('open');
				    	//三秒之后自动消失
					    	setTimeout(function(){
					    	$("#Dissa").window('close');
					    	$("#suppliers-win").window('close');
						}, 2000); 
				    	
				    	 
				    	$('#suppliers-dg').datagrid('reload');
				        $('#suppliers-form').form('clear');
				    
				    }
				}).submit();
			});
			
			//取消
			$("#cancel-suppliers").click(function() {
				 $('#suppliers-form').form('clear');
				 $("#suppliers-win").window('close');
			});	
			
			//供应商
			$('#suppliers-dg').datagrid({
				url : 'findall-supplier',
				pagination : true,
				pageNumber : 1,
				pageSize : 10,
				pageList : [ 10, 20 ],
				columns : [ [ 
					{field : 'supplierNumber',			title : '供应商编号',		width : 130}, 
					{field : 'supplierName',			title : '供应商名',			width : 140}, 
					{field : 'supplierLinkpeople',		title : '联系人',			width : 130}, 
					{field : 'supplierTel',				title : '联系电话',			width : 130}, 
					{field : 'supplierAddress',			title : '地址',				width : 180}, 
					{field : 'supplierTime',			title : '添加时间',			width : 150,formatter:comFormatDate}, 
					{field : 'nn',						title : '操作',				width : 165,
						formatter:function(value,row,index){
							   	var str="<a id='save-deletesuppliers' class='easyui-linkbutton' iconCls='icon-ok' onclick='deletesuppliers(this)'>禁用</a>"
							   	return str;
						}
					} 
				] ],
				onDblClickRow : function(rowIndex, rowData) {
					$("#update-suppliers-win").window("open");
					
					//获取供应商编号
					$("#suppliers-gysbh").textbox('setValue',rowData.supplierNumber);
					//获取供应商名
					$("#suppliers-gysmc1").textbox('setValue',rowData.supplierName);
					//获取负责人
					$("#suppliers-lxr1").textbox('setValue',rowData.supplierLinkpeople);
					//获取手机号
					$("#suppliers-lxdh2").textbox('setValue',rowData.supplierTel);
					//获取地址
					$("#suppliers-dz1").textbox('setValue',rowData.supplierAddress);
					//获取时间
					var st=rowData.supplierTime;
					var ts=CurentTime(st);
					$("#suppliers-tjsj").textbox('setValue',ts);

					
				}
					
			});
			
			$("#save-upsuppliers").click(function(){
				//获取供应商编号				
				var numb = $("#suppliers-gysbh").textbox("getValue");
				//获取联系人				
				var people = $("#suppliers-lxr1").textbox("getValue");
				//获取手机号				
				var phone = $("#suppliers-lxdh2").textbox("getValue");
				$.ajax({  
                    url: 'update-supp',  
                    data:{
                    	'numb':numb,
                    	'people':people,
                    	'phone':phone
                    },
                    type: 'POST',  
                    dataType:"json",
				 	success: function (data) {  
				 		$(".dissa").text("供应商修改成功！！！");
				    	$("#Dissa").window('open');
				    	//三秒之后自动消失
					    	setTimeout(function(){
					    	$("#Dissa").window('close');
					    	$("#update-suppliers-win").window('close');
						}, 2000); 
				    	$('#suppliers-dg').datagrid('reload');
				        $('#suppliers-form').form('clear');
				    	
				     }, 				     
                    Error: function () {  
                        alert(Error);  
                    }                   
                });  
				
			});
			
			$("#cancel-upsuppliers").click(function(){
				$("#update-suppliers-win").window("close");
			});
			
			//验证
			$.extend($.fn.textbox.defaults.rules, {
				    //姓名验证
					nameyz: {
				        validator: function(value, param) {
				            var reg = /^[\u4e00-\u9fa5]+$/i;
				            return reg.test(value);
				        },
				        message: "姓名请输入中文"
				    },
				    //手机号码验证
				    iphoneyz:{
				    	validator:function(value,param){
				    		 var regTel=/(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;
				    		 return regTel.test(value);
				    	},
				    	message:"请输入正确的手机号"
				    },
				    //地址验证
				    addyz:{
				    	validator: function(value, param) {
				            var addressreg = /^[\u4e00-\u9fa5]+$/i;
				            return addressreg.test(value);
				        },
				        message: "请输入正确的地址"
				    }
				    
		   });
			
		});
		
		// 时间戳
		function CurentTime(){
	  
	        var now = new Date();
	       
	        var year = now.getFullYear();       //年
	        var month = now.getMonth() + 1;     //月
	        var day = now.getDate();            //日
	       
	        var hh = now.getHours();            //时
	        var mm = now.getMinutes();          //分
			var ss = now.getSeconds();			//秒
	       
	        var clock = year + "-";
	       
	        if(month < 10)
	            clock += "0";
	       
	        clock += month + "-";
	       
	        if(day < 10)
	            clock += "0";
	           
	        clock += day + " ";
	       
	        if(hh < 10)
	            clock += "0";
	           
	        clock += hh + ":";
	        if (mm < 10) clock += '0'; 
	        clock += mm + ":"; 
			
	        if (ss < 10) clock += '0'; 
	        clock += ss; 
	        return(clock); 
		}
		
		//日期格式化
		function comFormatDate(date) {
			var day = new Date(date); 
			var Year = 0; 
			var Month = 0; 
			var Day = 0; 
			var CurrentDate = ""; 
			//初始化时间 
			Year= day.getFullYear();//ie火狐下都可以 
			Month= day.getMonth()+1; 
			Day = day.getDate(); 
			Hour = day.getHours(); 
			 Minute = day.getMinutes(); 
			 Second = day.getSeconds(); 
			CurrentDate += Year + "-"; 
			if (Month >= 10 ) { 
				CurrentDate += Month + "-"; 
			}else { 
				CurrentDate += "0" + Month + "-"; 
			} 
			if (Day >= 10 ) { 
				CurrentDate += Day ; 
			}else { 
				CurrentDate += "0" + Day ; 
			} 
			if(Hour>=10){
				CurrentDate +=" "+Hour;
			}else{
				CurrentDate +=" "+"0"+Hour;
			}
			if(Minute>=10){
				CurrentDate +=":"+Minute;
			}else{
				CurrentDate +=":"+"0"+Minute;
			}
			if(Second>=10){
				CurrentDate +=":"+Second;
			}else{
				CurrentDate +=":"+"0"+Second;
			}
			return CurrentDate; 
		}
		
	</script>

	<div id="suppliers-p" class="easyui-panel" style="width: 100%; height: 100%; padding: 10px; background: #fafafa;"
		data-options="iconCls:'icon-save',closable:true,collapsible:true,minimizable:true,maximizable:true">
		
		<p style="height: 40px; line-height: 30px; margin-right: 50px; float: right;">
			
			<a id="add-suppliers" class="easyui-linkbutton" iconCls="icon-add" plain="true">添加供应商</a>
		
		</p>

		<fieldset style="border: 1px solid #A6A6A6; border-radius: 6px; width: 1050px; margin: 0 auto;padding: 10px; margin-top: 10px; margin-bottom: 20px;">
			
			<legend style="font-size: 17px">供应商信息</legend>
			<table id="suppliers-dg" class="logininform-table easyui-datagrid" style="width: 1030px; height: 308px"
				data-options="toolbar:'#logininform-tb',fitColumns:false,singleSelect:false">
			
			</table>
		
		</fieldset>
	
	</div>

	<!-- 添加供应商窗口 -->
	<div id="suppliers-win" class="easyui-window" title="新增供应商" style="width: 550px; height: 450px"
		data-options="iconCls:'icon-save',closed:true,modal:true,shadow:true,resizable:false,collapsible:false,minimizable:false,maximizable:false">
		
		<div class="easyui-layout" data-options="fit:true">
			
			<form action="" method="post" id="suppliers-form" >
				
				<div data-options="region:'center'" style="padding: 30px;">
					
					<p style="height:60px; line-height: 20px;">
					
						<span style="margin-left: 80px;"></span>	
						
						<input id="suppliers-gysmc" name="supplierName" class="easyui-textbox" style="width: 280px" data-options="label:'供应商名称：',required:true"></input>										
					
					</p>
					
					<p style="height: 60px; line-height: 20px;">
					
						<span style="margin-left: 80px;"></span>	
					
						<input id="suppliers-dz" name="supplierAddress" class="easyui-textbox" style="width: 280px" data-options="label:'地址：',required:true,validType:['addyz']"></input>
					
					</p>
					
					<p style="height: 60px; line-height: 20px;">
						
						<span style="margin-left: 80px;"></span>
						
						<input id="suppliers-lxr" name="supplierLinkpeople" class="easyui-textbox" style="width: 280px" data-options="label:'联系人：',required:true,validType:['nameyz']"></input>
					
					</p>
					
					<p style="height: 60px; line-height: 20px;">
						
						<span style="margin-left: 80px;"></span>
						
						<input id="suppliers-lxdh" name="supplierTel" class="easyui-textbox" style="width: 280px" data-options="label:'联系电话：',required:true,validType:['iphoneyz']"></input>
					
					</p>
					
					<p style="margin-left: 100px;">
						
						<a style="width: 100px" id="save-suppliers" class="easyui-linkbutton" iconCls="icon-ok">添加</a> 
						
						<span style="margin-left: 50px;"></span>
						
						<a style="width: 100px" id="cancel-suppliers" class="easyui-linkbutton" iconCls="icon-cancel">取消</a>
					
					</p>
				
				</div>
			
			</form>
		
		</div>
	
	</div>

	<!-- 修改供应商窗口 -->
	<div id="update-suppliers-win" class="easyui-window" title="供应商修改" style="width: 630px; height: 430px"
		data-options="iconCls:'icon-save',closed:true,modal:true,shadow:true,resizable:false,collapsible:false,minimizable:false,maximizable:false">
		
		<div class="easyui-layout" data-options="fit:true">
			
			<div data-options="" style="padding: 30px;margin-left:40px;">

				<p style="height: 60px; line-height: 20px;">
					
					<input id="suppliers-gysbh" class="easyui-textbox" style="width: 200px" data-options="label:'供应商编号：',readonly:true"></input>
					
					<span style="margin-left: 50px;"></span>
					
					<input id="suppliers-tjsj" class="easyui-textbox" style="width: 200px" data-options="label:'添加时间：',readonly:true"></input>
				
				</p>

				<p style="height: 60px; line-height: 20px;">
					
					<input id="suppliers-gysmc1" class="easyui-textbox" style="width: 200px" data-options="label:'供应商名称：',readonly:true"></input>
					
					<span style="margin-left: 50px;"></span>
					
					<input id="suppliers-dz1" class="easyui-textbox" style="width: 200px" data-options="label:'地址：',readonly:true"></input>
				
				</p>
				
				<p style="height: 60px; line-height: 20px;">
					
					<input id="suppliers-lxr1" class="easyui-textbox" style="width: 200px;border: 1px red solid" data-options="label:'联系人：',required:true"></input> 
					
					<span style="margin-left: 50px;"></span>
					
					<input id="suppliers-lxdh2" class="easyui-textbox" style="width: 200px" data-options="label:'联系电话：',required:true,required:true,validType:['iphoneyz']"></input>
				
				</p>
				
				<p style="margin-left: 100px;">
					
					<a style="width: 100px" id="save-upsuppliers" class="easyui-linkbutton" iconCls="icon-ok">修改</a> 
					
					<span style="margin-left: 50px;"></span>
					
					<a style="width: 100px" id="cancel-upsuppliers" class="easyui-linkbutton" iconCls="icon-cancel">取消</a>
				
				</p>
			
			</div>
		
		</div>
	
	</div>
	
	<!-- 弹框提示 -->
	<div id="Dissa" class="easyui-window"  title="提示框" style="width:300px;height:156px"
	    data-options="iconCls:'icon-save',modal:true,resizable:false,collapsible:false,maximizable:false,minimizable:false,closed:true">
	          <p class="dissa" style="text-align:center;font-size: 16px;margin-top: 47px;">
	          </p>
	</div>

</body>
</html>